@inherits RenderViewPage
@using System.Web.Mvc.Html
@using Umbraco.Cms.Web
@using System.Xml
@using System.ServiceModel.Syndication
@using Umbraco.Framework.Dynamics
@using PBDesk.Business.FeedsAggregator
@using System
@{
    Layout = "_RootLayoutXml.cshtml";
    var home = DynamicModel.AncestorsOrSelf.First("NodeTypeAlias == @0", "HomePage");
    var all = home.DescendantsOrSelf.Where("UmbracoNaviHide == @0", "False");
}
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.sitemaps.org/schemas/sitemap-image/1.1"
        xmlns:video="http://www.sitemaps.org/schemas/sitemap-video/1.1">
    @foreach (var node in all)
    { @RenderNode(node) }
</urlset>
@helper RenderNode(BendyObject cNode)
    {
    if (cNode != null && cNode.AsDynamic().UmbracoNaviHide == "False")
    { 
     var url = cNode.AsDynamic().Url;
     var lastmod = cNode.AsDynamic().UtcModified.ToString("yyyy-MM-ddThh:mm:ss+00:00");
     var changefreq = cNode.AsDynamic().seoChangeFreq;
     var priority = cNode.AsDynamic().seoPriority;
    <url>
      @Render_loc(url)
      <lastmod>@lastmod</lastmod>
      @if(!string.IsNullOrEmpty(changefreq))
      {
      <changefreq>@changefreq</changefreq>
      }
      @if(!string.IsNullOrEmpty(priority))
      {
      <priority>@priority</priority>
      }
    </url>
    }
}
@helper Render_loc(string url)
    { 
    var cononicalUrl = String.Empty;
    if (Request.ServerVariables["HTTP_HOST"].ToLower().StartsWith("www"))
    { cononicalUrl = string.Concat("http://", Request.ServerVariables["HTTP_HOST"], url); }
    else
    { cononicalUrl = string.Concat("http://www.", Request.ServerVariables["HTTP_HOST"], url); }
    <loc>@cononicalUrl</loc>
}